package com.yq.light.data.code.controller;

import com.yq.light.commons.code.entity.CommonResult;
import com.yq.light.commons.code.entity.KnowledgeDb;
import com.yq.light.data.code.service.DataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/data")
@Slf4j
public class DataController {

    @Autowired
    private DataService dataService;

    @RequestMapping("/dataList")
    @ResponseBody
    public CommonResult dataList(@RequestParam("ownerAccount") String ownerAccount){
        log.info("ownerAccount --"+ownerAccount);
        try{
            List<KnowledgeDb> knowledgeDbList = dataService.dataList(ownerAccount);
            if(knowledgeDbList!=null){
                return new CommonResult(200,"获取数据成功",knowledgeDbList);
            }
        }catch (Exception e){
            log.error("DataController -dataList -error --"+e.toString());
        }
        return new CommonResult(200,"获取数据失败",null);
    }
}
